package be.phl.obstacleapp;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class ItemProblemRowAdapter extends ArrayAdapter<ItemProblem> {
	
	private final Context context;
	private final List<ItemProblem> ItemProblems;
	private boolean checkBoxEnabled;

	public boolean isCheckBoxEnabled() {
		return checkBoxEnabled;
	}

	public void setCheckBoxEnabled(boolean checkBoxEnabled) {
		this.checkBoxEnabled = checkBoxEnabled;
	}

	public ItemProblemRowAdapter(Context context, List<ItemProblem> ItemProblems, boolean checkBoxEnabled) {
		super(context, R.layout.item_problem_row, ItemProblems);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.ItemProblems = ItemProblems;
		this.checkBoxEnabled = checkBoxEnabled;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.item_problem_row, parent, false);
		
		TextView name = (TextView) rowView.findViewById(R.id.textView1);
		CheckBox Checked = (CheckBox) rowView.findViewById(R.id.checkBox1);
		
		ItemProblem itemProblem = ItemProblems.get(position);
		name.setText(itemProblem.getName());
		Checked.setChecked(false);
		
		if(!itemProblem.isBranchEnd()) {
			Checked.setEnabled(checkBoxEnabled);
			Checked.setVisibility(checkBoxEnabled ? 0:8);
		}
		
		return rowView;
	}
}
